package com.runvp.rest.auth;

import com.runvp.common.annotation.Log;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.enums.BusinessType;
import com.runvp.common.model.auth.LoginBody;
import com.runvp.common.model.auth.LoginUser;
import com.runvp.common.utils.validtion.ValidationUtils;
import com.runvp.service.auth.service.LoginService;
import com.runvp.service.auth.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * token 控制
 *
 * @author xkk update
 */
@Slf4j
@RestController
@RequestMapping("/app/auth")
public class TokenController extends BaseController {

    @Autowired
    private TokenService tokenService;

    @Autowired
    private LoginService loginService;
    /**
     * 发送验证码
     */
    @PostMapping("/send/code/{phone}")
    public AjaxResult sendCode(@PathVariable("phone") String phone) {
        return AjaxResult.success(phone);
    }
    /**
     * 登录
     */
    @Log(title = "登录", businessType = BusinessType.INSERT)
    @GetMapping("/login")
    public AjaxResult login(String username,String password) {
        // 用户登录
        LoginUser userInfo = loginService.login(username,password);
        // 获取登录token
        return AjaxResult.success(tokenService.createToken(userInfo));
    }
}
